package com.tiancheng.onecode.trade.enums;

import com.tiancheng.onecode.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 消息订阅的类型枚举
 *
 * @author kellen
 * @date 2024/5/22
 */
@Getter
@AllArgsConstructor
public enum MessageTypeEnum implements BaseEnum<String> {

    order_pay_result("order_pay_result", "订单支付结果"),
    order_refund_result("order_refund_result", "订单退款结果"),
    order_refund("order_refund", "异常退款"),
    order_coupon("order_coupon", "核销、释放优惠券"),
    order_sub_status_change("order_sub_status_change", "子订单状态流转"),
    order_invoice_items("order_invoice_items", "订单开票明细"),
    order_invoice_make("order_invoice_make", "订单开票明细开具发票"),
    invoice_result("invoice_result", "开票结果"),
    fund_auth_freeze("fund_auth_freeze", "信用订单预授权冻结"),
    fund_auth_unfreeze("fund_auth_unfreeze", "信用订单预授权解冻"),
    fund_auth_operation_cancel("fund_auth_operation_cancel", "信用订单预授权操作取消"),
    trade_status_sync("trade_status_sync", "信用订单授权转支付"),

    qrc_pay("qrc_pay", "二维码订单支付结果"),
    qrc_close("close_qr_order", "二维码订单关闭"),
    qrc_refund("qrc_refund", "二维码订单退款"),
    qrc_trade("qrc_trade", "二维码订单交易记录"),

    merchant_status("merchant_status", "商户状态变更通知"),

    trade_payment_settle_result("trade_payment_settle_result", "支付订单结算结果通知"),
    trade_payment_refund_settle_result("trade_payment_refund_settle_result", "支付退款订单结算结果通知"),
    ;

    private final String code;
    private final String name;

    public static Optional<MessageTypeEnum> getByCode(String code){
        return Arrays.stream(MessageTypeEnum.values()).filter(m -> m.getCode().equals(code)).findFirst();
    }
}
